<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <div>
        <div id="app">
            <p>
                <input type="text" v-model='userinfo.firstname' placeholder="姓">
            </p>
            <p>
                <input type="text" v-model='userinfo.lastname' placeholder="名">
            </p>
            <p>
                <input type="text" v-model='userinfo.fullname' placeholder="全名">
            </p>
        </div>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                userinfo: {
                    firstname: '',
                    lastname: '',
                    fullname: ''
                }
            },
            watch: {
                userinfo: {
                    handler(val) {
                        console.log(val)
                        this.userinfo.fullname = val.firstname + ' ' + this.userinfo.lastname
                        this.userinfo.fullname = this.userinfo.firstname + ' ' + val.lastname

                    },
                    // 如果数据不是首层 需要添加一个属性叫做deep  深度监听
                    deep: true
                }
            }
        })
    </script>
</body>

</html>